const express = require("express");
const passport = require("passport");
const bodyParser = require("body-parser");
const router = express.Router();
const stripeController = require("../controllers/stripeController");
const { verifyVisitorToken } = require("../middlewares/authMiddleware");

// 支付
router.post("/create-checkout-session", stripeController.createCheckoutSession);

// Stripe Elements 支付
router.post("/create-payment-intent", stripeController.createPaymentIntent); //一次性购买token
router.post("/create-subscription", stripeController.createSubscription); //订阅

// 取消订阅
router.post("/cancel-subscription", verifyVisitorToken, stripeController.cancelSubscription);
router.post("/cancel-subscription-immediately", verifyVisitorToken, stripeController.cancelSubscriptionImmediately);

// Stripe Webhook（必须用 raw！）
// router.post("/webhook", bodyParser.raw({type: 'application/json'}), stripeController.handleWebhook);

module.exports = router;
 